using System;
using NUnit.Framework;

namespace Org.JSON.Test
{
	[TestFixture]
	public class Manipulation
	{
		[Test]
		public void StringValue()
		{
			Assert.AreEqual("x", new Org.JSON.String("x").Value);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void StringNullValue()
		{
			new Org.JSON.String(null);
		}

		[Test]
		public void SingleTrueBoolean()
		{
			Assert.AreEqual(true, new Org.JSON.Boolean(true).Value);
		}

		[Test]
		public void SingleFalseBoolean()
		{
			Assert.AreEqual(false, new Org.JSON.Boolean(false).Value);
		}

		[Test]
		public void NumberValue()
		{
			Assert.AreEqual(1, new Org.JSON.Number(1).Value);
		}

		[Test]
		[ExpectedException(typeof(OverflowException))]
		public void ArrayRecursion()
		{
			var array = new Org.JSON.Array();
			array.Add(array);
		}

		[Test]
		[ExpectedException(typeof(OverflowException))]
		public void ArrayAndObjectRecursion()
		{
			var array = new Org.JSON.Array();
			var obj = new Org.JSON.Object();
			obj.Add("x", array);
			array.Add(obj);
		}

		[Test]
		[ExpectedException(typeof(OverflowException))]
		public void ObjectAndArrayRecursion()
		{
			var array = new Org.JSON.Array();
			var obj = new Org.JSON.Object();
			array.Add(obj);
			obj.Add("x", array);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void NullArrayAdd()
		{
			new Org.JSON.Array().Add(null);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void NullValueObjectAdd()
		{
			new Org.JSON.Object().Add("key", null);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void NullKeyObjectAdd()
		{
			new Org.JSON.Object().Add(null, new Org.JSON.Null());
		}

	}
}

